define(['moment'], function (moment) {
        return ['$scope', '$filter', '$mdDialog', 'config', 'MMWService', '$calculater', '$gallery', '$timeout',
            function ($scope, $filter, $mdDialog, config, $MMWService, $calculater, $gallery, $timeout) {
                $scope._event = {};
                $scope._fn = {};
                $scope.init = function () {  
                    $scope.B0501_ApplyType = "first_check";
                    $scope._nowForm = "";
                    $scope.qc_page = 'first_check';
                    $scope.qc_item = 'check_project';
                    $scope.re_apply_qc = false;
                    $scope.addRowParam = false;
                    $scope.datalist = [];
                    $scope.datalist = [];
                    $scope.pic_upload = false;
                    $scope.badCodeList = [];
                    $scope.condition = {
                        op_no : '',
                        op_name: '',
                        op_display : '',
                        machine_no: '',
                        serial_number: '',
                        station_no: '',
                        application_start: null,
                        application_end: null,
                        application_person: '',
                        plot_no: ''
                    };
                    var settings = JSON.parse(localStorage.getItem(config.appName + '_B0501_favourite_op_no') || '{}');
                    $scope.condition.op_no = settings.op_no || '';
                    $scope.condition.op_name = settings.op_name || '';
                    if ($scope.condition.op_no != '') {
                        $scope.condition.op_display = settings.op_no + ' (' + settings.op_name + ')';
                    }
                    $scope.applicationLog = [];
                    $scope.inspectionInfo = {
                        defect_qty: 0,
                        area_no: '',
                        qc_reason_detail: [],
                        checklist_detail: []
                    }
                    $scope.applyAreaShow = true;
                    $scope.secondTitle = "";
                    $scope.applyTypeName = $filter('translate')('B0501.first_check');
                    //20220601 add by wangzy M#0113089: 吉宏包装，质量检验-检验清单-界面不点进去输入复核明细也可以确认；请产中修改
                    $scope.showConfirmBtn = false;
                };
    
                $scope.changeApplyType = function () {
                    $scope.$root.showSelect({
                        title: $filter('translate')('common.msg.plz_select'),
                        label: 'display',
                        code: 'code',
                        selectCode: $scope.qc_page,
                        list: [
                            { display: $filter('translate')('B0501.first_check'), code: 'first_check' },
                            { display: $filter('translate')('B0501.last_check'), code: 'last_check' },
                            { display: $filter('translate')('B0501.re_check'), code: 're_check' }
                        ],
                        confirm: function (item, dialog) {
                            $scope.applyTypeName = item.display;
                            $scope.switchJY(item);                        
                            dialog.hide();
                        }
                    });
                };
                    // 搜索
                $scope._fn['B0501_Execute'] = {
                    click: () => {
                     $scope.OpenSearchForm();
                    }
                };

               // 点击跳转明细 
               $scope._event['B0501_datalist'] = {
                rowClick: (item) => {                 
                    $scope.changeFix(item);
                    $scope.pic_upload = false;
                    $scope.changeForm('B0501_Check_Detail');
                    $scope._event['B0501_Check_Detail_check_project'].isShown = 'Y';  // 项目检查
                    $scope._event['B0501_Check_Detail_bad_reason'].isShown = 'N';  // 不良现象
                    $scope._event['B0501_Check_Detail_apply_check_record'].isShown = 'N';  // 申请人检验记录
                    $scope._title = item.product_no + '｜' + item.product_name + '｜' + item.lot_no;
             
                }
               }; 
                // 我的最爱
                $scope._fn['B0501_Love_Execute'] = {
                click: () => {
                     $scope.favorite();
                     $scope._fn['B0501_B0501_Check_Detail'].isShown='Y';              
                  }
                };             
                // 申请类型
                $scope._event['B0501_ApplyType'] = {
                     click: (item) => {
                        $scope.B0501_ApplyType = item; 
                        $scope.switchJY(item);
                     }
                 }; 

                 
                $scope._fn['B0501_B0501_Check_Detail'] = { //開啟多人產量登入
                    isShown: ('B0214'=='B0214')?'Y':'Y',
                    click:()=>{
                    //     dialog.multiple_open();
                    $scope.changeForm('B0501_Check_Detail');
                    }
                 };
                  //申请人检验记录
                  $scope._fn['B0501_Check_Detail_Check_Project_Execute'] = {                      
                        click:()=>{
                           $scope.confirm();
                        }
                     };
                  // 不良现象
                  $scope._fn['B0501_Check_Detail_Bad_Reason_Execute'] = {                      
                        click:()=>{
                          $scope.confirm();
                        }
                     };

                // 20230217 add by Alan for #0127969: 補上重新自檢
                $scope._event['B0501_Check_Detail_re_apply_qc'] = {
                    isShown: 'N',
                    click: () => $scope.change_re_apply_qc()
                }

                $scope.$watch('qc_page', (newVal, oldVal) => {
                    if(newVal === 'last_check') {
                        $scope._event['B0501_Check_Detail_re_apply_qc'].isShown = 'Y'
                    } else {
                        $scope._event['B0501_Check_Detail_re_apply_qc'].isShown = 'N'
                    }
                });
                
                cbackToApplyArea = function () {
                    $scope.applyAreaShow = true;
                    //20220601 modify by wangzy for M#0113089: 吉宏包装，质量检验-检验清单-界面不点进去输入复核明细也可以确认
                    $scope.showConfirmBtn = false;
                };
    
                $scope.back = function () {
                    $scope.$root.hideMenu();
                    $scope.$root.changeProgram('home', true);
                };
    
                $scope.switchJY = function (info) {
                    $scope.qc_page = info;
                    // 清空
                    $scope.datalist = [];
                    $scope.condition.machine_no = '';
                    $scope.condition.serial_number = '';    
                    $scope.condition.station_no = '';
                    $scope.condition.application_start = null;
                    $scope.condition.application_end = null;
                    $scope.condition.application_person = '';
                    $scope.condition.plot_no = '';
                    $scope.picSrcArray = [];
                    $scope.applicationLog = [];
                    $scope.inspectionInfo.qc_reason_detail = [];
                    $scope.inspectionInfo.checklist_detail = [];
                    $scope.badCodeList = [];
                };
    
                $scope.switchItem = function (item) {
                    $scope.qc_item = item;
                    if(item == 'check_project'){
                        $scope.pic_upload = false;
                        $scope.addRowParam = false;
                       
                        $scope._event['B0501_Check_Detail_check_project'].isShown = 'Y';  // 项目检查
                        $scope._event['B0501_Check_Detail_bad_reason'].isShown = 'N';  // 不良现象
                        $scope._event['B0501_Check_Detail_apply_check_record'].isShown = 'N';  // 申请人检验记录
                      
                     } else if(item == 'pic_upload') {
                       


                        $scope.pic_upload = true;
                        $scope.addRowParam = false;
                        $scope._event['B0501_Check_Detail_check_project'].isShown = 'N';  // 项目检查
                        $scope._event['B0501_Check_Detail_bad_reason'].isShown = 'N';  // 不良现象
                        $scope._event['B0501_Check_Detail_apply_check_record'].isShown = 'N';  // 申请人检验记录
                     } else if(item == 'bad_reason') {


                        $scope.pic_upload = false;
                        $scope._event['B0501_Check_Detail_check_project'].isShown = 'N';  // 项目检查
                        $scope._event['B0501_Check_Detail_bad_reason'].isShown = 'Y';  // 不良现象
                        $scope._event['B0501_Check_Detail_apply_check_record'].isShown = 'N';  // 申请人检验记录
                        $scope.addRowParam = true;
                     } else {


                        $scope.addRowParam = false;
                        $scope.pic_upload = false;
                        $scope._event['B0501_Check_Detail_check_project'].isShown = 'N';  // 项目检查
                        $scope._event['B0501_Check_Detail_bad_reason'].isShown = 'N';  // 不良现象
                        $scope._event['B0501_Check_Detail_apply_check_record'].isShown = 'Y';  // 申请人检验记录
                     }
                };
    
                $scope.favorite = function(callback){
                    if(config.setting.OperatingArea==''){
                        $scope.$root.showAlert($filter('translate')('home.showAlert'));
                        return;
                    }
                    $MMWService.showQueryListPNIG({
                        form_name: 'PageNo_33',
                        mode:'M',
                        key:'page_no',
                        header : [
                            {label: $filter('translate')('common.queryList.op_c'), code:'page_no'},
                            {label: $filter('translate')('common.queryList.op_n'), code:'page_name'}
                        ],
                        selectKey:{key:'favourite', true:'1', false:'0'},
                        setCondition:function(conditions){
                            conditions.push({column_name:'B.MASTERNO', query_mode:'0', value:config.setting.OperatingArea, merge_condition_model:'AND' });
                            return conditions;
                        },
                        confirm: function(selectItem, dialog){
                            var content = {
                                master_type: 5,
                                master_no :config.setting.OperatingArea,
                                favourite_qc_op_detail:[]
                            };
                            if(selectItem && selectItem.length>0){
                                selectItem.forEach(function(item){
                                    if(item.favourite == '1'){
                                        content.favourite_qc_op_detail.push({op_no:item.page_no});
                                    }
                                });
                            }
                            beforeSaveFavorite(content.favourite_qc_op_detail, function(){
                                $MMWService.sendToServer({
                                    uri: 'ServicesSTD.Module_SYS.favourite_machine_process',
                                    content : content,
                                    success : function(data){
                                        dialog.hide();
                                        $scope.$root.showToast($filter('translate')('B0214_F.msg.saveSucess'));
                                        if(callback)
                                            callback();
                                    }
                                });
                            });
                        }
                    });
                };
    
                function beforeSaveFavorite(favoriteList, callback){
                    var isDeleteCurrentOp = false;
                    if($scope.condition.op_no && $scope.condition.op_no != ''){
                        if(favoriteList && favoriteList.length > 0){
                            var filterList = $filter('filter')(favoriteList, {op_no: $scope.condition.op_no}, true);
                            if(filterList.length == 0){
                                isDeleteCurrentOp = true; //使用者將"目前的作業站"從我的最愛移除了
                            }
                        }
                    }
    
                    if(isDeleteCurrentOp){
                        $scope.$root.showAlert($filter('translate')('B0501.msg.favorite_remove'),function(){
                            $scope.condition.op_no = '';
                            $scope.condition.op_name = '';
                            $scope.condition.machine_no = '';
                            $scope.condition.op_display = '';
                            $scope.condition.plot_no = '';
                             //20220606  modify by liuyang for M#112901: 吉宏包装，质量检验-待检清单，我的最爱设定后查询检验单后报错
                             $scope.inspectionInfo = {
                                defect_qty: 0,
                                area_no: '',
                                qc_reason_detail: [],
                                checklist_detail: []
                            };
                            localStorage.setItem(config.appName + '_B0501_favourite_op_no', JSON.stringify({op_no:$scope.condition.op_no, op_name:$scope.condition.op_name}));
                            if(callback)
                                callback();
                        });
                    }else{
                        if(callback)
                            callback();
                    }
                }
    
                $scope.confirm = function () {
                    if ($scope.datalist.filter(d => d.is_select).length == 0) {
                        $scope.$root.showAlert($filter('translate')('common.msg.plz_select_one'));
                        return;
                    }
                    var defect_qty = 0, msg = '';
                    //20200831 modify by Dustdusk for M#77210:
                    $scope.inspectionInfo.qc_reason_detail.forEach(function(item, index){
                        //此項目須判斷是否要輸入不良
                        // 20231221 modify by wenwei for M#153794: [MSSQL] [H5][首巡自末检]质量检验检验项目不合格是否需要录入不良问题
                        if(item.is_inputscrap == '1'){
                            // switch btn 沒選過 / false
                            if(item.check_type == 0 && (item.reason_value == '' || item.reason_value == 'false')){
                                // 檢查不良現象是否有新增不良原因
                                if(dialog.inspectionInfo.checklist_detail.length == 0){
                                    msg += $filter('translate')('B0207.check_list.column1') + item.reason_no + '、';
                                }
                            } else if(item.check_type == 1){
                                // 有輸入值
                                if(item.reason_value !== '' && item.reason_value !== null) {
                                    // 符合標準
                                    if((+item.mini_value) <= (+item.reason_value) && (+item.reason_value) <= (+item.max_value)) return
                                }
                                // 檢查不良現象是否有新增不良原因
                                if(dialog.inspectionInfo.checklist_detail.length == 0){
                                    msg += $filter('translate')('B0207.check_list.column1') + item.reason_no + '、';
                                }
                            }
                        }
                    });
    
                    if(msg != ''){
                        if($scope.inspectionInfo.checklist_detail.length == 0){
                            $scope.$root.showAlert(msg + $filter('translate')('B0207.msg.checkitem_need_badreason'));
                            return;
                        }
                    }
    
                    $scope.inspectionInfo.checklist_detail.forEach(function(item, index){
                        item.item_seq = index;
                        defect_qty = $calculater.decimalAdd(defect_qty, item.item_qty);
                    });
    
                    let selectRow = $scope.datalist.filter(d => d.is_select);
                    var sumQty = selectRow[0].check_qty;
                    if ((+defect_qty) > (+sumQty)) {
                        msg = $filter('translate')('B0501.msg.check_qty_lt_defect_qty');
                    } 
    
                    if (msg == '') {
                        $scope.inspectionInfo.defect_qty = defect_qty;
                        firstPieceCheckProcess();
                    } else {
                        $scope.$root.showAlert(msg);
                    }
                };
    
                // 修改重新自检
                $scope.change_re_apply_qc = function () {
                    // 20230217 add by Alan for #0127969: 補上重新自檢
                    // 页签是末检申请且有录入不良现象才可点击
                    if ($scope.qc_page == 'last_check'){
                        $scope.re_apply_qc = !$scope.re_apply_qc;
                        $scope.B0501_Check_Detail_re_apply_qc = $scope.re_apply_qc.toString() ;
                    }
                };
                
                //查詢 - 作業站開窗
                //改為右側搜尋表單
                
                $scope.loadOpNo = function (dd) {
                    $scope.$root.showQueryList({
                        header: [
                            {label:$filter('translate')('common.queryList.op_c'), code:'page_no'},
                            {label:$filter('translate')('common.queryList.op_n'), code:'page_name'}
                        ],
                        query: function(conditions, feedback){
                            var content = {
                                form_name: 'PageNo_33',
                                query_condition_info: []
                            };
                            if(config.setting.OperatingArea != ''){
                                content.query_condition_info.push({column_type:'29', query_mode:'0', value:config.setting.OperatingArea, merge_condition_model:'AND' });
                            }
                            //20180525 modify by 李栋 for mantis#0047129
                            $MMWService.pageNumberInfoGet(
                                {
                                    form_name: 'PageNo_33',
                                    query_condition_info:[
                                        {column_name:'B.MASTERNO', query_mode:'0', value:config.setting.OperatingArea, merge_condition_model:'AND' }
                                    ]
                                },function(data){
                                    var temp = $filter('filter')(data, {favourite:'1'});
                                    //var temp = data.page_number_info_get;
                                    if(temp && temp.length){
                                        feedback(temp);
                                    } else {
                                        $scope.$root.showConfirm($filter('translate')('B0501.msg.favorite_empty'), function(confirmDialog){
                                            confirmDialog.hide();
                                            $timeout(function(){
                                                $scope.favorite(function(){
                                                    $scope.loadOpNo();
                                                });
                                            }, 200);
                                        });
                                    }
                                }
                            );
                        },
                        selectCode:$scope.condition.op_no||'',
                        confirm : function(selectItem, dialog){
                            $scope.condition.op_display = selectItem.page_no + ' ('+selectItem.page_name+')';
                            $scope.condition.op_no = selectItem.page_no;
                            $scope.condition.op_name = selectItem.page_name;
                            localStorage.setItem(config.appName + '_B0501_favourite_op_no', JSON.stringify({op_no:$scope.condition.op_no, op_name:$scope.condition.op_name}));
                            dialog.hide();
                        }
                    });
                };                        
    
                //查詢 - 生產批開窗
                $scope.loadPlotInfo = function () {
                    $MMWService.showQueryListPNIG({
                        form_name:"PageNo_41",
                        condition: [
                            { name: $filter('translate')('common.queryList.plot_no'), column_name: 'LotNo', query_mode: '2', value: '' }
                        ],
                        setCondition: function (conditions) {
                            conditions.push({ column_name: 'OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                            if ($scope.qc_page == 'first_check') {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                            } else if ($scope.qc_page == 'last_check') {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                            } else {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                            }
                            return conditions;
                        },
                        header: [
                            {label:$filter('translate')('common.queryList.plot_no'), code:'page_no'}
                        ],
                        selectCode:$scope.condition.plot_no,
                        confirm : function(selectItem){
                            $scope.condition.plot_no = selectItem.page_no;
                        }
                    });
                };
    
                //设备编号开窗
                //改為右側搜尋表單
                $scope.loadMachineNo = function () {
                    $MMWService.showQueryListPNIG({
                        form_name: 'PageNo_42',
                        condition: [
                            { name: $filter('translate')('common.queryList.machine_c'), column_name: 'a.EquipmentNo', query_mode: '2', value: '' }
                        ],
                        setCondition: function (conditions) {
                            conditions.push({ column_name: 'a.OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                            if ($scope.condition.plot_no != '') {
                                conditions.push({ column_name: 'a.LOTNO', query_mode: '0', value: $scope.condition.plot_no, merge_condition_model: 'AND' });
                            }
                            if ($scope.qc_page == 'first_check') {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                            } else if ($scope.qc_page == 'last_check') {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                            } else {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                            }
                            return conditions;
                        },
                        header: [
                            { label: $filter('translate')('common.queryList.machine_c'), code: 'page_no' },
                            { label: $filter('translate')('common.queryList.machine_n'), code: 'page_name' }
                        ],
                        selectCode: $scope.condition.machine_no,
                        confirm: function (selectItem) {
                            $scope.condition.machine_no = selectItem.page_no;
                        }
                    });
                };
    
                // 工位开窗
                $scope.loadStationNo = function () {
                    var query_condition_info = [];
                    query_condition_info.push({ column_name: 'a.OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                    if ($scope.condition.plot_no != '') {
                        query_condition_info.push({ column_name: 'a.LOTNO', query_mode: '0', value: $scope.condition.plot_no, merge_condition_model: 'AND' });
                    }
                    if ($scope.qc_page == 'first_check') {
                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                    } else if ($scope.qc_page == 'last_check') {
                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                    } else {
                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                    }
                    $MMWService.pageNumberInfoGet({
                        form_name:"PageNo_43",
                        query_condition_info: query_condition_info
                    }, function (response) {
                        $scope.showSelect({
                            title: $filter('translate')('common.msg.plz_select'),
                            label: function (item) {
                                return item.page_no;
                            },
                            code: 'page_no',
                            selectCode: $scope.condition.station_no,
                            list: response,
                            confirm: function (selected, d) {
                                d.hide();
                                $scope.condition.station_no = selected.page_no;
                            }
                        });
                    })
                }
    
                //申请人开窗
                $scope.loadApplicationNo = function () {
                    $MMWService.showQueryListPNIG({
                        form_name: 'PageNo_44',
                        condition: [
                            { name: $filter('translate')('common.queryList.employee_c'), column_name: 'a.Creator', query_mode: '2', value: '' }
                        ],
                        setCondition: function (conditions) {
                            conditions.push({ column_name: 'a.OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                            if ($scope.condition.plot_no != '') {
                                conditions.push({ column_name: 'a.LOTNO', query_mode: '0', value: $scope.condition.plot_no, merge_condition_model: 'AND' });
                            }
                            if ($scope.qc_page == 'first_check') {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                            } else if ($scope.qc_page == 'last_check') {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                            } else {
                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                            }
                            return conditions;
                        },
                        header: [
                            { label: $filter('translate')('common.queryList.employee_c'), code: 'page_no' },
                            { label: $filter('translate')('common.queryList.employee_n'), code: 'page_name' }
                        ],
                        selectCode: $scope.condition.application_person,
                        confirm: function (selectItem) {
                            $scope.condition.application_person = selectItem.page_no;
                        }
                    });
                };
    
                //成品序号开窗
                $scope.loadSerialNo = function () {
                    var query_condition_info = [];
                    query_condition_info.push({ column_name: 'a.OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                    if ($scope.condition.plot_no != '') {
                        query_condition_info.push({ column_name: 'a.LOTNO', query_mode: '0', value: $scope.condition.plot_no, merge_condition_model: 'AND' });
                    }
                    if ($scope.qc_page == 'first_check') {
                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                    } else if ($scope.qc_page == 'last_check') {
                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                    } else {
                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                    }
                    $MMWService.pageNumberInfoGet({
                        form_name: 'PageNo_45',
                        query_condition_info: query_condition_info
                    }, function (response) {
                        $scope.showSelect({
                            title: $filter('translate')('common.msg.plz_select'),
                            label: function (item) {
                                return item.page_no;
                            },
                            code: 'page_no',
                            selectCode: $scope.condition.serial_number,
                            list: response,
                            confirm: function (selected, d) {
                                d.hide();
                                $scope.condition.serial_number = selected.page_no;
                            }
                        });
                    })
                };
    
                $scope.QRcodeScanner = function(){
                    $scope.$root.OpenScanner({
                        after : function(result){
                            if(result.text && result.text!=''){
                                var temp = result.text.split(';');
                                if(temp.length>1){
                                    $scope.condition.op_no = temp[1]||'';
                                }
                                if(temp.length>0){
                                    $scope.condition.plot_no = temp[0]||'';
                                }
                                $scope.search();
                            }
                        },
                        exception: function(){
                            //目前裝置無法使用相機
                            $scope.$root.showAlert($filter('translate')('B0214.showAlert.column3'));
                        },
                        orientation : 'landscape'
                    });
                }
    
                //查詢 - 確認
                $scope.search = function () {
                    if ($scope.condition.op_no.length == 0) {
                        $scope.$root.showAlert($filter('translate')('B0501.msg.plot_no_empty'));
                    } else {
                        // 查询待检清单
                        var content = {
                            apply_qc_type: $scope.qc_page == 'first_check' ? '2' : ($scope.qc_page == 'last_check' ? '4' : '6'),
                            op_no: $scope.condition.op_no,
                            lot_no: $scope.condition.plot_no,
                            equipment_no: $scope.condition.machine_no,
                            position_no: $scope.condition.station_no,
                            creator: $scope.condition.application_person,
                            application_start: $scope.condition.application_start ? FormatDate($scope.condition.application_start) : '',
                            application_end: $scope.condition.application_end ? FormatDate($scope.condition.application_end) : '',
                            pcs_no: $scope.condition.serial_number
                        }
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.piece_check_get',
                            content: content,
                            success: function (data) {
                                if (data.pieceList.length == 0) {
                                    $scope.datalist = [];
                                    $scope.datalist= [];
                                    $scope.picSrcArray = [];
                                    $scope.applicationLog = [];
                                    $scope.inspectionInfo.qc_reason_detail = [];
                                    $scope.inspectionInfo.checklist_detail = [];
                                    $scope.badCodeList = [];
                                    $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                                } else {
                                    data.pieceList.forEach(p => {
                                        if (p.qc_result == 'Y') {
                                            p.qc_result_n = $filter('translate')('B0501.qualified');
                                        } else if (p.qc_result == 'N') {
                                            p.qc_result_n = $filter('translate')('B0501.unqualified');
                                        }
                                        if (p.qc_item_result == 'Y') {
                                            p.qc_item_result_n = $filter('translate')('B0501.qualified');
                                        } else if (p.qc_item_result == 'N') {
                                            p.qc_item_result_n = $filter('translate')('B0501.unqualified');
                                        }
                                    });
                                    $scope.datalist = data.pieceList;
                                    $scope.datalist.forEach(d => d.is_select = false);
                                    $scope.datalist[0].is_select = true;
                                    $scope.itemClick($scope.datalist[0]);
                                }
                            }
                        });
                    }
                };
    
                $scope.changeFix = function (item) {
                    $scope.datalist.forEach(d => d.is_select = false);
                    item.is_select = true;
                    $scope.itemClick(item);
                    $scope.applyAreaShow = false;
                    //20220601 modify by wangzy M#	0113089: 吉宏包装，质量检验-检验清单-界面不点进去输入复核明细也可以确认；请产中修改
                    $scope.showConfirmBtn = true;
                    $scope.secondTitle = item.product_no + '｜' + item.product_name + '｜' + item.lot_no;
                }
    
                $scope.itemClick = function (item) {
                    $scope.inspectionInfo.checklist_detail = [];
                    $MMWService.pageNumberInfoGet({
                        form_name: 'PageNo_8',
                        query_condition_info : [
                            { column_name: 'OPNo', query_mode: '0', value: item.op_no }
                        ]
                    }, function(itemList){
                        $scope.badCodeList = itemList;
                        opqcreason_info_get({ plot_no: item.lot_no, op_no: item.op_no }, function (data) {
                            $scope.server_url = 'http://' + config.server.ip + ':' + config.server.port;
                            $scope.inspectionInfo.qc_reason_detail = data.qc_reason_detail || [];
                            $scope.inspectionInfo.area_no = data.area_no;
                            // 检验人记录
                            $MMWService.pageNumberInfoGet({
                                form_name: 'PageNo_47',
                                query_condition_info: [
                                    { column_name: 'A.QCFormNo', query_mode: '0', value: item.qc_form_no }
                                ]
                            }, function (dataLog) {
                                if (dataLog.length > 0) {
                                    dataLog.forEach(d => {
                                        if (d.inputvalue == 'true') {
                                            d.inputvalue_n = $filter('translate')('B0501.qualified');
                                        } else if (d.inputvalue == 'false') {
                                            d.inputvalue_n = $filter('translate')('B0501.unqualified');
                                        } else{
                                            //20210326 by jason 0088452: [ORACLE][H5][3.03.01]质量检验-申请人检验记录
                                            d.inputvalue_n = d.inputvalue;
                                        }
                                    });
                                }
                                $scope.applicationLog = dataLog || [];
                            });
                        });
                    });
                };
    
                function FormatDate(date) {
                    let seperator1 = "/";
                    let year = date.getFullYear();
                    let month = date.getMonth() + 1;
                    let strDate = date.getDate();
                    if (month >= 1 && month <= 9) {
                        month = "0" + month;
                    }
                    if (strDate >= 0 && strDate <= 9) {
                        strDate = "0" + strDate;
                    }
                    let currentdate = year + seperator1 + month + seperator1 + strDate;
                    return currentdate;
                }
    
                //不良原因開窗
                $scope.loadInspectionReasonList = function (item) {
                    // 是否选中单头数据
                    if ($scope.datalist.filter(d => d.is_select).length == 0){
                        $scope.$root.showAlert($filter('translate')('common.msg.plz_select_one'));
                        return;
                    }
                    $scope.$root.showQueryList({
                        key:'page_no',
                        selectCode:item?item.page_no:'',
                        header : [
                            {label: $filter('translate')('common.queryList.badReason_c'), code:'page_no'},
                            {label: $filter('translate')('common.queryList.badReason_n'), code:'page_name'}
                        ],
                        query: function(conditions, feedback){
                            feedback($scope.badCodeList);
                        },
                        confirm: function (selectItem, radioDialog) {
                            if(item != undefined){
                                item.item_code = selectItem.page_no;
                                item.page_no = selectItem.page_no;
                                item.page_name = selectItem.page_name;
                            } else {
                                $scope.inspectionInfo.checklist_detail.push({
                                    item_code: selectItem.page_no,
                                    page_no : selectItem.page_no,
                                    page_name : selectItem.page_name,
                                    item_qty: 1,
                                    item_seq: ''
                                });
                            }
                            radioDialog.hide();
                        }
                    });
                };
    
                $scope.addRow = function () {
                    $scope.loadInspectionReasonList();
                };
    
                $scope.removeRow = function (index) {
                    $scope.inspectionInfo.checklist_detail.splice(index, 1);
                };
    
                $scope.input_defect_qty = function (event, item) {
                    var target = event.currentTarget;
                    angular.element(target).addClass('is-focus');
                    $calculater.open(function (num, calDialog) {
                            angular.element(target).removeClass('is-focus');
                            calDialog.hide();
                            item.item_qty = num;
                            //$scope.inspectionInfo.defect_qty = $scope.inspectionInfo.defect_qty + parseInt(num) - parseInt(oriNum);
    
                        },
                        function (calDialog) {
                            angular.element(target).removeClass('is-focus');
                            calDialog.hide();
                        },
                        {
                            defaultNum: item.item_qty,
                            decimalLength: 3
                        });
                };
    
                $scope.InRange = function(item){
                    if(item.check_type == 1 && !isNaN(item.reason_value)){
                        if((+item.mini_value) <= (+item.reason_value)
                            && (+item.reason_value) <= (+item.max_value)){
                            return true;
                        } else {
                            return false;
                        }
                    } else {
                        return false;
                    }
                };
    
                //送出結果
                function firstPieceCheckProcess() {
                    // 获取选中行
                    let selectRow = $scope.datalist.filter(d => d.is_select);
                    var content = {
                        machine_no: selectRow[0].equipment_no ? selectRow[0].equipment_no : 'N/A',
                        pcsno: selectRow[0].pcs_no,
                        position_no: selectRow[0].position_no,
                        station_no: $scope.condition.op_no,
                        op_no: $scope.condition.op_no,
                        plot_no: selectRow[0].lot_no,
                        employee_no: config.cache.account,
                        creator: config.cache.account,
                        area_no: $scope.inspectionInfo.area_no,
                        check_qty: selectRow[0].check_qty,
                        defect_qty: $scope.inspectionInfo.defect_qty,
                        check_time: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
                        origin_qc_form_no: selectRow[0].qc_form_no,
                        qc_result: 'Y',
                        apply_qc_type: ($scope.qc_page == 'last_check' && $scope.re_apply_qc) ? '5' : '',
                        qc_type: $scope.qc_page == 'first_check' ? '-1' : ($scope.qc_page == 'last_check' ? '-4' : '-6'),
                        type: $scope.qc_page == 'first_check' ? '0' : ($scope.qc_page == 'last_check' ? '4' : '6'),
                        checklist_detail: $scope.inspectionInfo.checklist_detail,
                        image_detail: [],
                        qc_reason_detail: $scope.inspectionInfo.qc_reason_detail,
                        run_type: 1
                    };
    
                    if((+content.defect_qty) != 0)
                        content.qc_result = 'N';
    
                    for(var i=0;i<$scope.picSrcArray.length;i++){
                        var picSrc = $scope.picSrcArray[i];
                        content.image_detail.push({
                            image_src:picSrc,
                            image_seq:i,
                            image_format:'jpg'
                        });
                    }
                    $MMWService.sendToServer({
                        uri: 'ServicesSTD.Module_WIP.first_piece_check_process',
                        content: content,
                        success: function () {
                            $scope.$root.showToast($filter('translate')('common.msg.success'));
                            $scope.re_apply_qc = false;
                            //20220601 modify by wangzy for M#0113089: 吉宏包装，质量检验-检验清单-界面不点进去输入复核明细也可以确认
                            $scope.applyAreaShow = true;
                            $scope.showConfirmBtn = false;
                            $scope.changeForm('B501');
                            // 重新查询刷新
                            $scope.search();
                        }
                    });
                }
    
                function opqcreason_info_get(content, feedback) {
                    var type = $scope.qc_page == 'first_check' ? '0' : ($scope.qc_page == 'last_check' ? '4' : '6')
                    $MMWService.sendToServer({
                        uri: 'ServicesSTD.Module_WIP.op_qcreason_info_get',
                        content: {
                            op_no: content.op_no,
                            lot_no: content.plot_no,
                            machine_no: '',
                            area_no: '',
                            type: type
                        },
                        success: function (data) {
                            if(feedback)
                                feedback(data);
                        }
                    });
                }
    
                var picLimitNum = 5;
                $scope.picSrcArray = [];
                //拍照
                $scope.pic_add = function($event){
                    if($scope.picSrcArray.length < picLimitNum){
                        if(typeof(navigator.camera) !== 'undefined'){
                            //回傳URI
                            navigator.camera.getPicture(
                                function(imageURI) {
                                    
                                    if($scope.$root.compressImage)
                                    {
                                        $scope.$root.compressImage(imageURI, 
                                            function(data){  
                                                $scope.picSrcArray.push(data);
                                                $scope.$apply();
                                                }); 
                                    }
                                    else
                                    {
                                        $scope.picSrcArray.push(imageURI);
                                        $scope.$apply();
                                    }
                                    //$scope.data.scrollLeft = document.getElementById('img-tile-list').clientWidth;
                                },
                                function(message) {
                                    //alert('Failed because: ' + message);
                                },
                                {
                                    quality: 50,
                                    destinationType: Camera.DestinationType.DATA_URL
                                }
                            );
                        } else if(window.nodeRequire){
                            //回傳URI
                            $scope.$root.FileDialog({
                                callback:function(fileList){
                                    $scope.$root.showLoading();
                                    $scope.$apply();
                                    setTimeout(function(){
                                        if(fileList){
                                            if(fileList.length == 0){
                                                //
                                            } else if(($scope.picSrcArray.length + fileList.length) > picLimitNum){
                                                $scope.$root.showAlert($filter('translate')('B0501.msg.pic_limit', {num:picLimitNum}));
                                            } else {
                                                var fs = window.nodeRequire('fs');
                                                fileList.forEach(function(fileName){
                                                    var image = fs.readFileSync(fileName);
                                                    if(image)
                                                    {
                                                        if($scope.$root.compressImage)
                                                        {
                                                            $scope.$root.compressImage(new Buffer(image).toString('base64'), 
                                                            function(data){$scope.picSrcArray.push(data)}); 
                                                        }
                                                        else
                                                        {
                                                            $scope.picSrcArray.push(new Buffer(image).toString('base64'))
                                                        }
                                                    }
                                                });
                                            }
                                        }
                                        $scope.$root.hideLoading();
                                        $scope.$apply();
                                    });
                                }
                            });
                        } else {
                            $scope.$root.showAlert($filter('translate')('common.msg.cant_use_camera'));
                        }
                    } else {
                        $scope.$root.showAlert($filter('translate')('B0501.msg.pic_limit', {num:picLimitNum}));
                    }
                };
    
                $scope.pic_delete = function(index){ 
                    $scope.picSrcArray.splice(index,1);
                };
    
                $scope.pic_open = function(index){
                    $gallery.show('#'+(index+1), 'data:image/jpeg;base64,'+$scope.picSrcArray[index], function(){});
                };
    
                $scope.open_checkPic = function(item){
                    $gallery.show(item.reason_no, $scope.server_url+item.picture_path, function(){});
                };
    
                //20211028 add by 翰鴻 for mantis#97211            
                $scope.OpenSearchForm = function () {
                    $mdDialog.dialog('module/moduleB/program/B05/B0501/SearchForm.tmp.html',
                        function (dialog) {
                            return {
                                css_url: 'module/moduleB/program/B05/B0501/SearchForm.css', //此开窗所需要使用的CSS档案位置
                                //temp : 'A', //利用dialog.temp即可取得目前temp的值
                                //开窗程序载入完成以后会呼叫此function
                                beforeShown:function(){
                                    //do something
                                },
                                //右上角的X会呼叫此function
                                back: function () {
                                    dialog.hide();//利用此dialog
                                },
                                condition: $scope.condition,
                                loadOpNo: function () {
                                    $scope.$root.showQueryList({
                                        header: [
                                            {label:$filter('translate')('common.queryList.op_c'), code:'page_no'},
                                            {label:$filter('translate')('common.queryList.op_n'), code:'page_name'}
                                        ],
                                        query: function(conditions, feedback){
                                            var content = {
                                                form_name: 'PageNo_33',
                                                query_condition_info: []
                                            };
                                            if(config.setting.OperatingArea != ''){
                                                content.query_condition_info.push({column_type:'29', query_mode:'0', value:config.setting.OperatingArea, merge_condition_model:'AND' });
                                            }
                                            //20180525 modify by 李栋 for mantis#0047129
                                            $MMWService.pageNumberInfoGet(
                                                {
                                                   form_name: 'PageNo_33',
                                                    query_condition_info:[
                                                        {column_name:'B.MASTERNO', query_mode:'0', value:config.setting.OperatingArea, merge_condition_model:'AND' }
                                                    ]
                                                },function(data){
                                                    var temp = $filter('filter')(data, {favourite:'1'});
                                                    //var temp = data.page_number_info_get;
                                                    if(temp && temp.length){
                                                        feedback(temp);
                                                    } else {
                                                        $scope.$root.showConfirm($filter('translate')('B0501.msg.favorite_empty'), function(confirmDialog){
                                                            confirmDialog.hide();
                                                            $timeout(function(){
                                                                $scope.favorite(function(){
                                                                    $scope.loadOpNo();
                                                                });
                                                            }, 200);
                                                        });
                                                    }
                                                }
                                            );
                                        },
                                        selectCode:$scope.condition.op_no||'',
                                        confirm : function(selectItem, s_dialog){
                                            dialog.condition.op_display = selectItem.page_no + ' (' + selectItem.page_name + ')';
                                            dialog.condition.op_no = selectItem.page_no;
                                            dialog.condition.op_name = selectItem.page_name;
                                            localStorage.setItem(config.appName + '_B0501_favourite_op_no', JSON.stringify({op_no:$scope.condition.op_no, op_name:$scope.condition.op_name}));
                                            s_dialog.hide();
                                        }
                                    });
                                }, // loadOpNo End
                                loadMachineNo : function () {
                                    $MMWService.showQueryListPNIG({
                                        form_name: 'PageNo_42',
                                        condition: [
                                            { name: $filter('translate')('common.queryList.machine_c'), column_name: 'a.EquipmentNo', query_mode: '2', value: '' }
                                        ],
                                        setCondition: function (conditions) {
                                            conditions.push({ column_name: 'a.OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                                            if ($scope.condition.plot_no != '') {
                                                conditions.push({ column_name: 'a.LOTNO', query_mode: '0', value: $scope.condition.plot_no, merge_condition_model: 'AND' });
                                            }
                                            if ($scope.qc_page == 'first_check') {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                                            } else if ($scope.qc_page == 'last_check') {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                                            } else {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                                            }
                                            return conditions;
                                        },
                                        header: [
                                            { label: $filter('translate')('common.queryList.machine_c'), code: 'page_no' },
                                            { label: $filter('translate')('common.queryList.machine_n'), code: 'page_name' }
                                        ],
                                        selectCode: $scope.condition.machine_no,
                                        confirm: function (selectItem) {
                                            dialog.condition.machine_no = selectItem.page_no;
                                        }
                                    });
                                }, //loadMachineNo End
                                loadSerialNo : function () {
                                    var query_condition_info = [];
                                    query_condition_info.push({ column_name: 'a.OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                                    if ($scope.condition.plot_no != '') {
                                        query_condition_info.push({ column_name: 'a.LOTNO', query_mode: '0', value: $scope.condition.plot_no, merge_condition_model: 'AND' });
                                    }
                                    if ($scope.qc_page == 'first_check') {
                                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                                    } else if ($scope.qc_page == 'last_check') {
                                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                                    } else {
                                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                                    }
                                    $MMWService.pageNumberInfoGet({
                                        form_name: 'PageNo_45',
                                        query_condition_info: query_condition_info
                                    }, function (response) {
                                        $scope.showSelect({
                                            title: $filter('translate')('common.msg.plz_select'),
                                            label: function (item) {
                                                return item.page_no;
                                            },
                                            code: 'page_no',
                                            selectCode: $scope.condition.serial_number,
                                            list: response,
                                            confirm: function (selected, d) {
                                                d.hide();
                                                dialog.condition.serial_number = selected.page_no;
                                            }
                                        });
                                    })
                                }, // loadSerialNo End
                                loadPlotInfo : function () {
                                    $MMWService.showQueryListPNIG({
                                        form_name: 'PageNo_41',
                                        condition: [
                                            { name: $filter('translate')('common.queryList.plot_no'), column_name: 'LotNo', query_mode: '2', value: '' }
                                        ],
                                        setCondition: function (conditions) {
                                            conditions.push({ column_name: 'OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                                            if ($scope.qc_page == 'first_check') {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                                            } else if ($scope.qc_page == 'last_check') {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                                            } else {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                                            }
                                            return conditions;
                                        },
                                        header: [
                                            {label:$filter('translate')('common.queryList.plot_no'), code:'page_no'}
                                        ],
                                        selectCode:$scope.condition.plot_no,
                                        confirm : function(selectItem){
                                            dialog.condition.plot_no = selectItem.page_no;
                                        }
                                    });
                                }, // loadPlotInfo End
                                loadStationNo : function () {
                                    var query_condition_info = [];
                                    query_condition_info.push({ column_name: 'a.OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                                    if ($scope.condition.plot_no != '') {
                                        query_condition_info.push({ column_name: 'a.LOTNO', query_mode: '0', value: $scope.condition.plot_no, merge_condition_model: 'AND' });
                                    }
                                    if ($scope.qc_page == 'first_check') {
                                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                                    } else if ($scope.qc_page == 'last_check') {
                                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                                    } else {
                                        query_condition_info.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                                    }
                                    $MMWService.pageNumberInfoGet({
                                        form_name: 'PageNo_43',
                                        query_condition_info: query_condition_info
                                    }, function (response) {
                                        $scope.showSelect({
                                            title: $filter('translate')('common.msg.plz_select'),
                                            label: function (item) {
                                                return item.page_no;
                                            },
                                            code: 'page_no',
                                            selectCode: $scope.condition.station_no,
                                            list: response,
                                            confirm: function (selected, d) {
                                                d.hide();
                                                dialog.condition.station_no = selected.page_no;
                                            }
                                        });
                                    })
                                }, //loadStationNo End
                                loadApplicationNo : function () {
                                    $MMWService.showQueryListPNIG({
                                        form_name: 'PageNo_44',
                                        condition: [
                                            { name: $filter('translate')('common.queryList.employee_c'), column_name: 'a.Creator', query_mode: '2', value: '' }
                                        ],
                                        setCondition: function (conditions) {
                                            conditions.push({ column_name: 'a.OPNO', query_mode: '0', value: $scope.condition.op_no, merge_condition_model: 'AND' });
                                            if ($scope.condition.plot_no != '') {
                                                conditions.push({ column_name: 'a.LOTNO', query_mode: '0', value: $scope.condition.plot_no, merge_condition_model: 'AND' });
                                            }
                                            if ($scope.qc_page == 'first_check') {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 2, merge_condition_model: 'AND' });
                                            } else if ($scope.qc_page == 'last_check') {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 4, merge_condition_model: 'AND' });
                                            } else {
                                                conditions.push({ column_name: 'ApplyQcType', query_mode: '0', value: 6, merge_condition_model: 'AND' });
                                            }
                                            return conditions;
                                        },
                                        header: [
                                            { label: $filter('translate')('common.queryList.employee_c'), code: 'page_no' },
                                            { label: $filter('translate')('common.queryList.employee_n'), code: 'page_name' }
                                        ],
                                        selectCode: $scope.condition.application_person,
                                        confirm: function (selectItem) {
                                            dialog.condition.application_person = selectItem.page_no;
                                        }
                                    });
                                }, //loadApplicationNo End
                                search: function () {
                                    $scope.$root.showLoading();
                                    
                                    if (dialog.condition.op_no.length == 0) {
                                        $scope.$root.showAlert($filter('translate')('B0501.msg.plot_no_empty'));
                                    } else {
                                        // 查询待检清单
                                        var content = {
                                            apply_qc_type: $scope.qc_page == 'first_check' ? '2' : ($scope.qc_page == 'last_check' ? '4' : '6'),
                                            op_no: dialog.condition.op_no,
                                            lot_no: dialog.condition.plot_no,
                                            equipment_no: dialog.condition.machine_no,
                                            position_no: dialog.condition.station_no,
                                            creator: dialog.condition.application_person,
                                            application_start: dialog.condition.application_start ? FormatDate(dialog.condition.application_start) : '',
                                            application_end: dialog.condition.application_end ? FormatDate(dialog.condition.application_end) : '',
                                            pcs_no: dialog.condition.serial_number
                                        }
                                        $MMWService.sendToServer({
                                            uri: 'ServicesSTD.Module_WIP.piece_check_get',
                                            content: content,
                                            success: function (data) {
                                                if (data.pieceList.length == 0) {
                                                    $scope.datalist = [];
                                                    $scope.picSrcArray = [];
                                                    $scope.applicationLog = [];
                                                    $scope.inspectionInfo.qc_reason_detail = [];
                                                    $scope.inspectionInfo.checklist_detail = [];
                                                    $scope.badCodeList = [];
                                                    $scope.$root.showAlert($filter('translate')('common.msg.no_data'));
                                                } else {
                                                    data.pieceList.forEach(p => {
                                                        if (p.qc_result == 'Y') {
                                                            p.qc_result_n = $filter('translate')('B0501.qualified');
                                                        } else if (p.qc_result == 'N') {
                                                            p.qc_result_n = $filter('translate')('B0501.unqualified');
                                                        }
                                                        if (p.qc_item_result == 'Y') {
                                                            p.qc_item_result_n = $filter('translate')('B0501.qualified');
                                                        } else if (p.qc_item_result == 'N') {
                                                            p.qc_item_result_n = $filter('translate')('B0501.unqualified');
                                                        }
                                                    });
                                                    $scope.datalist=data.pieceList;
                                                    $scope.datalist = data.pieceList;
                                                    $scope.datalist.forEach(d => d.is_select = false);
                                                    $scope.datalist[0].is_select = true;
                                                    $scope.itemClick($scope.datalist[0]);
                                                    
                                                    dialog.hide()
                                                }
                                            }
                                        });
                                    }
                                    $scope.$root.hideLoading();
                                }, //search End
                                QRcodeScanner : function(){
                                    $scope.$root.OpenScanner({
                                        after : function(result){
                                            if(result.text && result.text!=''){
                                                var temp = result.text.split(';');
                                                if(temp.length>1){
                                                    dialog.condition.op_no = temp[1]||'';
                                                }
                                                if(temp.length>0){
                                                    dialog.condition.plot_no = temp[0]||'';
                                                }
                                                dialog.search();
                                            }
                                        },
                                        exception: function(){
                                            //目前裝置無法使用相機
                                            $scope.$root.showAlert($filter('translate')('B0214.showAlert.column3'));
                                        },
                                        orientation : 'landscape'
                                    });
                                } //QRcodeScanner End
                            }
                    });
                }
            }
        ];
    });
    